﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GcmpDbCommonEdit.h"
#include "ElementId.h"

namespace gcmp
{
    class IDocument;
    class Vector3d;
    class IPolyCurve;
    class Coordinate3d;
    class IElementBreakBehavior;
    class ICurve3d;
    class IPlane;

    /// \brief 对象打断返回结果
    struct GCMP_DB_COMMON_EDIT_EXPORT BreakElementResult
    {
        ElementId NewId;                ///<  新生成的Element的Id
        std::wstring BreakStatus;       ///<  打断后可能存在的弱提示内容
    };

    /// \brief 打断工具类
    class GCMP_DB_COMMON_EDIT_EXPORT BreakUtils
    {
    public:
        /// \brief 打断对象
        ///
        /// \param pDocument 当前文档
        /// \param breakElementId 被打断对象的Id
        /// \param breakPoint 被打断对象定位线上的打断点
        /// \param pElementBreakBehavior 对象打断行为,用户要实现打断功能需先定制该行为，给空则没有打断功能
        /// \return BreakElementResult 对象打断返回结果对象
        /// \see IElementBreakBehavior
        static BreakElementResult BreakElement(
            IDocument * pDocument,
            const ElementId & breakElementId,
            const Vector3d & breakPoint,
            IElementBreakBehavior * pElementBreakBehavior
        );

        /// \brief 单点打断多段线对象
        ///
        /// \param pPolyCurve 被打断的多段线几何数据
        /// \param breakPoint 被打断对象定位线上的打断点
        /// \param coord  多段线所在坐标系
        /// \param opCurvesResult 打断生成新的多段线对象集合
        /// \return true 打断成功 false 打断失败
        static bool BreakPolyCurve(const IPolyCurve* pPolyCurve,const Vector3d &breakPoint,const Coordinate3d& coord,std::vector<OwnerPtr<IPolyCurve>>& opCurvesResult);

        /// \brief 两点打断多段线对象
        ///
        /// \param pPolyCurve 被打断的多段线对象
        /// \param breakPoint1 被打断对象定位线上的打断点1
        /// \param breakPoint2 被打断对象定位线上的打断点2
        /// \param coord  当前视图平面的坐标系对象
        /// \param opCurvesResult 打断生成新的多段线对象集合
        /// \return true 打断成功 false 打断失败
        static bool BreakPolyCurveBy2Pt(const IPolyCurve* pPolyCurve, const Vector3d& breakPoint1, const Vector3d& breakPoint2, const Coordinate3d& coord, std::vector<OwnerPtr<IPolyCurve>>& opCurvesResult);

        /// \brief 两点打断Curve3d对象
        ///
        /// \param pCurve3d 被打断的Curve3d对象
        /// \param breakPoint1 被打断对象定位线上的打断点1
        /// \param breakPoint2 被打断对象定位线上的打断点2
        /// \param pPlane  被打断对象所在平面
        /// \param opCurvesResult 打断生成新的Curve3d集合
        /// \return true 打断成功 false 打断失败
        static bool BreakCurve3dBy2Pt(const ICurve3d* pCurve3d, const Vector3d& breakPoint1, const Vector3d& breakPoint2, const IPlane* pPlane, std::vector<OwnerPtr<ICurve3d>>& opCurvesResult);

        GCMP_OBSOLETE_API(2022 / 07 / 01, BreakUtils::BreakPolyCurve(const IPolyCurve*, const Vector3d &, const Coordinate3d&, std::vector<OwnerPtr<IPolyCurve>>&)) static bool BreakPolyCurve(IDocument* pDoc,
            const OwnerPtr<IPolyCurve> opPolyCurve,const Vector3d &breakPoint,const Coordinate3d& coord,double tolerance,std::vector<OwnerPtr<IPolyCurve>>& opCurvesResult);
        GCMP_OBSOLETE_API(2022 / 07 / 01, BreakUtils::BreakPolyCurveBy2Pt(const IPolyCurve*, const Vector3d &, const Vector3d&, const Coordinate3d&, std::vector<OwnerPtr<IPolyCurve>>&)) static bool BreakPolyCurveBy2Pt(IDocument* pDoc,
            const OwnerPtr<IPolyCurve> opPolyCurve, const Vector3d& breakPoint1, const Vector3d& breakPoint2, const Coordinate3d& coord, double tolerance, std::vector<OwnerPtr<IPolyCurve>>& opCurvesResult);
    };
}
